package com.huifaapp.mall.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.SPUtils;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.huifaapp.mall.R;
import com.huifaapp.mall.adapter.InvitationVipRecordListviewAdapter;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.bean.InvitationVIP;
import com.huifaapp.mall.bean.InvitationVIPRecordBean;
import com.huifaapp.mall.uitils.AUniqueIdentifier;
import com.huifaapp.mall.uitils.UtilsImage;
import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

/**
 * Created by Administrator on 2018/1/22.
 */

public class InvitationVIPRecordActivity extends AppCompatActivity{

    private PullToRefreshListView pulllv_vip_invitation;
    private ImageView iv_vip_record_image;
    private ImageView iv_vip_record_userImage;
    private TextView tv_vip_record_UserName;
    private TextView tv_vip_record_yundianzhu;
    private ImageView iv_vip_record_back;
    private TextView tv_vip_record_yaoqingVIP;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vip_invitation_vip_record);
        pulllv_vip_invitation= (PullToRefreshListView) findViewById(R.id.pulllv_vip_invitation);
        iv_vip_record_image= (ImageView) findViewById(R.id.iv_vip_record_image);
        iv_vip_record_userImage= (ImageView) findViewById(R.id.iv_vip_record_userImage);
        tv_vip_record_UserName= (TextView) findViewById(R.id.tv_vip_record_UserName);
        tv_vip_record_yundianzhu= (TextView) findViewById(R.id.tv_vip_record_yundianzhu);
        iv_vip_record_back= (ImageView) findViewById(R.id.iv_vip_record_back);
        iv_vip_record_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        tv_vip_record_yaoqingVIP= (TextView) findViewById(R.id.tv_vip_record_yaoqingVIP);
        tv_vip_record_yaoqingVIP.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(InvitationVIPRecordActivity.this,InvitationVIPActivity.class);
                startActivity(intent);
                finish();
            }
        });
        iv_vip_record_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(InvitationVIPRecordActivity.this,InvitationVIPActivity.class);
                startActivity(intent);
                finish();
            }
        });
        InvitelaodVIPRecord();

    }
    private void InvitelaodVIPRecord(){
        Log.e("邀请","url=============="+ ApiManager.USERS_INVITE_LISTVIP+"?token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+ AUniqueIdentifier.getDeviceId(InvitationVIPRecordActivity.this));
        OkHttpUtils.get().url(ApiManager.USERS_INVITE_LISTVIP+"?token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+AUniqueIdentifier.getDeviceId(InvitationVIPRecordActivity.this))
                .build()
                .execute(new StringCallback() {

                    @Override
                    public void onError(Request request, Exception e) {

                    }

                    @Override
                    public void onResponse(String response) {
                        Gson gson = new Gson();
                        InvitationVIPRecordBean list = gson.fromJson(response,InvitationVIPRecordBean.class);
                        if(list.getCode().equals("10000")){
                            UtilsImage.uploadimageview(iv_vip_record_userImage,list.getData().getFirst().getUserHeadImg(),"",InvitationVIPRecordActivity.this);
                            tv_vip_record_UserName.setText(list.getData().getFirst().getUserNickName());
                            if(list.getData().getFirst().getType().equals("002")){
                                tv_vip_record_yundianzhu.setVisibility(View.VISIBLE);
                            }else {
                                tv_vip_record_yundianzhu.setVisibility(View.GONE);
                            }
                            InvitationVipRecordListviewAdapter adapter=new InvitationVipRecordListviewAdapter(InvitationVIPRecordActivity.this,list.getData().getList());
                            pulllv_vip_invitation.setAdapter(adapter);
                        }else if(list.getCode().equals("10001")){
                            Intent intent=new Intent(InvitationVIPRecordActivity.this,LoginActivity.class);
                            startActivity(intent);
                        }else{
                            Toast.makeText(InvitationVIPRecordActivity.this,list.getMsg(),Toast.LENGTH_SHORT).show();
                        }

                    }
                });
    }
}
